package com.itheima.controller;

import com.itheima.exception.BusinessException;
import com.itheima.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    /**
     * 其他异常处理器
     */
    @ExceptionHandler(Exception.class)
    public Result doException(Exception ex) {
        System.out.println("发生了其他异常！！！");

        return new Result(Code.OTHER_EXCEPTION , null , ex.getCause().toString());
    }

    /**
     * 系统异常处理器
     */
    @ExceptionHandler(SystemException.class)
    public Result doSystemException(Exception ex) {
        System.out.println("发生了系统异常！！！");

        return new Result(Code.SYSTEM_EXCEPTION , null , ex.getMessage());
    }

    /**
     * 业务异常处理器
     */
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(Exception ex) {
        System.out.println("发生了业务异常！！！");

        return new Result(Code.BUSINESS_EXCEPTION , null , "发生了其他异常！！！");
    }

}
